<?php
namespace app\admin\model;

use think\Exception;
use think\facade\Db;
use think\Model;
use think\model\concern\SoftDelete;

//订单页
class Order extends Model{
    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $pk='order_id';
    //order  订单列表sql语句
     public static function  ordersList($where,$data){
         $order=Order::
            alias('o')
             ->field("o.order_id,o.order_sn,o.buyer_name,o.goods_amount,o.add_time")
             ->field("s.order_status")
             ->field("p.payment_name")
             ->join('order_status s','o.status=s.status_id')
             ->join('payment p','o.payment_id=p.payment_id')
             ->where($where)
             ->paginate([
                 'list_rows'=>5,
                 'query'=>$data
             ]);
         return $order;
         }
    //订单状态表
    public static function   orderStatus(){
        $ostatus=Order::suffix('_status')->field(true)->select();
        return $ostatus;
    }
    //获取器
    public static function   getAddTimeTextAttr($v,$data){
         return date('Y-m-d H:i:s',$data['add_time']);
       }

    //订单列表删除处理(软删)
     public static function   orderDel($get){
         try{
             $res=Order::destroy($get['id']);
         }catch (\Exception $e){
             $res=false;
         }
            return $res;

     }

    //订单列表多个删除处理(软删)
      public static function   orderAllDel($get){
          try{
              $get['id']=explode(',', $get['id']);
              foreach ($get['id'] as $v){
                  $res=Order::destroy($v);
              }
          }catch (\Exception $e){
              $res=false;
          }
          return $res;



      }

    //订单页回收站列表展示
     public static function   orderRecycle(){
     $list=Order::onlyTrashed()
         ->alias('o')
         ->field("o.order_id,o.order_sn,o.buyer_name,o.goods_amount,o.add_time")
         ->field("s.order_status")
         ->field("p.payment_name")
         ->join('order_status s','o.status=s.status_id')
         ->join('payment p','o.payment_id=p.payment_id')
         ->select()->toArray();

      return $list;

     }

     //订单页回收站删除
     public static function   orderHuiDel($get){
         try{
             $res=Order::destroy($get['id'],true);
         }catch (\Exception $e){
             $res=false;
         }
         return $res;

     }

     //订单页回收站恢复
     public static function   orderHuiFu($get){
         try{
             $res=Order::onlyTrashed()->find($get['id']);
             $res->restore();
         }catch (\Exception $e){
            $res=false;
             //  echo $e->getMessage();

         }
         return $res;

     }




}

